package com.example.designpatten.chapter7_proxypatten;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

public class StaticProxy {
    public static void main(String[] args) {
        SchoolGril mm = new SchoolGril("jiaojiao");
        Proxy proxy = new Proxy(mm);
        proxy.giveDolls();
        proxy.giveFlowers();
        proxy.giveChocolate();
    }

    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    static
    class SchoolGril{
        private String name;
    }

    //送礼物
    interface GiveGift {
        void giveDolls();
        void giveFlowers();
        void giveChocolate();
    }

    static class Pursuit implements GiveGift {
        private SchoolGril mm;

        public Pursuit(SchoolGril mm) {
            this.mm = mm;
        }

        @Override
        public void giveDolls() {
            System.out.println(mm.getName() + " 送你洋娃娃");
        }

        @Override
        public void giveFlowers() {
            System.out.println(mm.getName() + " 送你鲜花");
        }

        @Override
        public void giveChocolate() {
            System.out.println(mm.getName() + " 送你巧克力");
        }
    }

    static class Proxy implements GiveGift {
        private Pursuit pursuit;

        public Proxy(SchoolGril mm) {
            pursuit = new Pursuit(mm);
        }

        @Override
        public void giveDolls() {
            pursuit.giveDolls();
            System.out.println("额外做一些操作");
        }

        @Override
        public void giveFlowers() {
            pursuit.giveFlowers();
        }

        @Override
        public void giveChocolate() {
            pursuit.giveChocolate();
        }
    }
}
